<?php session_start(); ?>
<?php include 'db.php' ?>
<html>
<head>
<title>
	HK Pool - Pool your hobby goodies
</title>
<link href="Styles/colorbox.css" rel="stylesheet" type="text/css" />
<link href="Styles/default.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-latest.min.js" language="javascript" type="text/javascript">
</script>
<script src="js/jquery.colorbox.js" language="javascript" type="text/javascript">
</script>
<script src="js/hkpool.js" language="javascript" type="text/javascript">
</script>
<script language="javascript" type="text/javascript">

$(document).ready(function(){
	$(".tab-content").hide();
	$(".tab-content:first").show();
	$("#top-menu td").click(function(){
		$(".tab-content").hide();
        var activeTab = $(this).find("a").attr("href");
        $(activeTab).fadeIn();
	});
	defaultIfEmpty("#new-wt", "Enter Target Wt.");
	defaultIfEmpty("#new-order-dt", "Enter Ordering Date");
	defaultIfEmpty("#find-wt", "Enter Wt.");
	
	//drive via session variable
	<?php
	if($_SESSION["loggedin"]==0){
	?>
		$.colorbox({ overlayClose:false, iframe: true, width: "800px", height: "400px", href:"login.php", closeButton:false, escKey:false, arrowKey:false});
		$(document).bind('cbox_closed', function(){ document.location.href= 'default.php'; });
	<?php 
	} 
	?>
});
</script>
</head>
<?php
$connection = mysqli_connect($db_host, $db_username, $db_password, $db_catalog);
if (mysqli_connect_errno())
{
	echo "Cannot open database connection. Please try again later. ". mysqli_connect_error();
	die();
}
?>
<body>
<div id="header">
	<table width="100%">
		<tr>
			<td width="70%">
				<span style="color:#000080; padding:10px;font-size:7.0em;font-family:Courier, Times New Roman, Verdana;">hk-pool</span>
			</td>
			<td>
				<?php
				$query = "SELECT name FROM people where id =".$_SESSION["loggedin"];
				$result = mysqli_query($connection, $query);
				$row = mysqli_fetch_array($result);
				if($row){
					echo "Welcome ".$row['name'];
				}
				?>
				<a style="background:#000080;padding:10px;" href="logout.php">Log out</a>
			</td>
		</tr>
	</table>
</div>
<div id="main">
	<table id="top-menu">
		<tr>
		<td>
				<a href="#tabYourPools">Your Pools</a>
			</td>
			<td>
				<form action="default.php?action=newPool" method="post">
					<a href="#tabNewPool">New Pool</a><br/>
					<input type="text" id="new-wt" name="new-wt" value="Enter Target Wt."><br/>
					<input type="text" id="new-order-dt" name="new-order-dt" value="Enter Ordering Date"><br/>
					<input type="submit" value="Go">
				</form>
			</td>
			<td>	
				<form action="default.php?action=findPool" method="post">
					<a href="#tabFindPools">Find Pools</a><br/>
					<input type="text" id="find-wt" name="find-wt" value="Enter Wt.">
					<input type="button" value="Go">
				</form>
			</td>
			
		</tr>
	</table>
	<br/>
	<br/>
	<div id="tabNewPool" class="tab-content">	<!--show latest pools -->
		<b>Recent Pools</b>
		<table>
			<form>
				<table class="pool-list">
						<thead class="pool-list">
							<td>Pool</td>
							<td>Available Wt.</td>
							<td>Confirmed</td>
						</thead>
						<?php
							$query = "SELECT * FROM pool ORDER BY created DESC";
							$result = mysqli_query($connection, $query);
							while($row = mysqli_fetch_array($result)){
								echo "<tr>";
								echo "<td>".$row['id']."</td>";
								echo "<td>".$row['available_wt']."</td>";
								echo "<td>&nbsp;</td>";
								echo "</tr>";
								}
						?>
					</table>
			</form>
			
		</table>
	</div>
	<div id="tabFindPools" class="tab-content">	<!--show latest pools -->
		<b>Find Results</b>
		<table>
			<form >
				
			</form>
		</table>
	</div>
	<div id="tabYourPools" class="tab-content">
		<table>
			<thead>
				<td><b>Pools you've requested in<b></td>
				<td></td>
				<td><b>Pools you've created<b></td>
			</thead>
			<tr>
				<td width="50%" valign="top">
					<table class="pool-list">
						<thead class="pool-list">
							<td>Pool</td>
							<td>Created By</td>
							<td>Available Wt.</td>
							<td>Status</td>
						</thead>
						<?php
							$index = 4;
								while(--$index > 0){
						?>
						<tr>
							<td><?php echo $index ?></td>
							<td>Username</td>
							<td><?php echo ($index * 30 + 0.9) ?></td>
						</tr>
						<?php }
						?>
					</table>
				</td>
				<td style="border-left:1px solid black;"></td>
				<td width="50%" valign="top">
					<table class="pool-list">
						<thead class="pool-list">
							<td>Pool</td>
							<td>Available Wt.</td>
							<td>Confirmed</td>
						</thead>
						<?php
							$query = "SELECT * FROM pool WHERE created_by=".$_SESSION["loggedin"];
							$result = mysqli_query($connection, $query);
							while($row = mysqli_fetch_array($result)){
								echo "<tr>";
								echo "<td>".$row['id']."</td>";
								echo "<td>".$row['available_wt']."</td>";
								echo "<td>&nbsp;</td>";
								echo "</tr>";
								}
						?>
					</table>
				</td>
			</tr>
		</table>
	</div>
</div>
<div id="rules">
<b>Between the lines...</b>
<br/><br/>
<p><i>There are no lines. We're together responsible for using or abusing this system. However, here's what you can do to play fair</i></p>
<br/>
<p>
Creating a shipping pool:
<ol>
	<li>When you create a pool, make sure you have a target ordering date </li>
	<li>Please ensure that you are satisfied with your transactions before complaining that someones's turned his back on you!</li>
</ol>
Requesting inclusion in a shipping pool:
<ol>
	<li>One can request for inclusion in upto 3 pools</li>
	<li>Inclusion/Rejection from a pool is solely a choice the pool creator so don't complain!</li>
</ol>
</p>
</div>
</body>
</html>

<?php mysqli_close($connection); ?>